package indi.kider.server.bill.api;

import com.google.gson.Gson;
import indi.kider.common.constant.EmployeeRoleCons;
import indi.kider.common.model.bill.*;
import indi.kider.common.model.employee.Employee;
import indi.kider.server.bill.model.PayState;
import indi.kider.server.bill.service.BillService;
import indi.kider.server.bill.service.related.AuthcService;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.vankid.common.model.base.CommonResponse;
import pers.vankid.common.utils.page.PageRequest;
import pers.vankid.common.utils.page.PageResponse;

import java.util.Arrays;
import java.util.List;

/**
 * Created by shixj on 2018/5/7.
 */
@RestController
@RequestMapping("bill")
@Log4j
public class BillController {

    //查询账单
    //自动模式结算
    @Autowired
    private BillService billService;
    @Autowired
    private AuthcService authcService;

    /**
     * @api {PUT} bill
     * @apiGroup balance-bill
     * @apiDescription 后台定时结算（内部服务）
     * @apiParamExample 请求样例：
     * http://localhost:9002/balance-bill/bill
     * {}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"请求成功！","data":[{"id":1,"billType":1,"payState":0,"billTime":"2018-05-10 08:58:53","payTime":null,"billAttribution":1,"lastRead":"22","lastReadTime":"2018-05-10 08:59:02","thisRead":"22","thisReadTime":"2018-05-10 08:59:05","absoluteNumber":"121","price":"1","total":"1","paySerial":""}]}
     */
    @PutMapping("")
    public CommonResponse autoBalance() {
        billService.balance();
        return CommonResponse.buildDefaultSuccessResponse("");
    }

    /**
     * @api {PUT} bill/payState
     * @apiGroup balance-bill
     * @apiDescription 更新支付状态及流水 tenantId;//登录租客、好友ID
     * @apiParamExample 请求样例：
     * http://localhost:9002/balance-bill/bill/payState
     * {"payState": 1,"payTime":"2018-05-10","paySerial":"11111","payType:"1,""billId":[1],"tenantId":1}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"202","msg":"保存成功！","data":{"id":1,"billType":null,"payState":1,"billTime":null,"payTime":"2018-05-10 08:00:00","billAttribution":null,"lastRead":null,"lastReadTime":null,"thisRead":null,"thisReadTime":null,"absoluteNumber":null,"price":null,"total":null,"paySerial":"11111"}}
     */
    @PutMapping("payState")
    public CommonResponse updatePayStatus(@RequestBody BillPay billPay) {
        try {
            log.info("更新支付状态及流水的入参【" + new Gson().toJson(billPay) + "】");
            billService.updatePayStatus(billPay);
            return CommonResponse.buildUpdateSuccessResponse("");
        } catch (Exception e) {
            return CommonResponse.buildExceptionResponse(e);
        }

    }

    /**
     * @api {GET} bill/{billId}
     * @apiGroup balance-bill
     * @apiDescription 根据账单ID获取账单信息
     * @apiParamExample 请求样例：
     * http://localhost:9002/balance-bill/bill/1
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":{"id":1,"billType":1,"payState":0,"billTime":"2018-05-10 08:58:53","payTime":null,"billAttribution":1,"lastRead":"22","lastReadTime":"2018-05-10 08:59:02","thisRead":"22","thisReadTime":"2018-05-10 08:59:05","absoluteNumber":"121","price":"1","total":"1","paySerial":""}}
     */
    @GetMapping("{billId}")
    public CommonResponse queryOne(@PathVariable Long billId) {
        return CommonResponse.buildGetSuccessResponse(billService.queryOne(billId));
    }

    /**
     * @api {POST} bill/list
     * @apiGroup balance-bill
     * @apiDescription 查询账单（分页）
     * @apiParamExample 请求样例：
     * http://localhost:9002/balance-bill/bill/list
     * {"num":"0","size":"8","query":{"id":1,"billType":1,"payState":0,"billTime":"2018-05-10 08:58:53","payTime":null,"billAttribution":1,"lastRead":"22","lastReadTime":"2018-05-10 08:59:02","thisRead":"22","thisReadTime":"2018-05-10 08:59:05","absoluteNumber":"121","price":"1","total":"1","paySerial":""}}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":{"rows":[{"id":1,"billType":1,"payState":0,"billTime":"2018-05-10 08:58:53","payTime":null,"billAttribution":1,"lastRead":"22","lastReadTime":"2018-05-10 08:59:02","thisRead":"22","thisReadTime":"2018-05-10 08:59:05","absoluteNumber":"121","price":"1","total":"1","paySerial":""}],"total":1,"size":0}}
     */
    @PostMapping("list")
    public CommonResponse<PageResponse> query(@RequestBody PageRequest<Bill> request) {
        return CommonResponse.buildGetSuccessResponse(billService.query(request));
    }

    /**
     * @api {POST} bill/all
     * @apiGroup balance-bill
     * @apiDescription 查询账单（不分页）
     * @apiParamExample 请求样例：
     * http://localhost:9002/balance-bill/bill/all
     * {"id":1,"billType":1,"payState":0,"billTime":"2018-05-10 08:58:53","payTime":null,"billAttribution":1,"lastRead":"22","lastReadTime":"2018-05-10 08:59:02","thisRead":"22","thisReadTime":"2018-05-10 08:59:05","absoluteNumber":"121","price":"1","total":"1","paySerial":""}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":[{"id":1,"billType":1,"payState":0,"billTime":"2018-05-10 08:58:53","payTime":null,"billAttribution":1,"lastRead":"22","lastReadTime":"2018-05-10 08:59:02","thisRead":"22","thisReadTime":"2018-05-10 08:59:05","absoluteNumber":"121","price":"1","total":"1","paySerial":""}]}
     */
    @PostMapping("all")
    public CommonResponse query(@RequestBody Bill bill) {
        return CommonResponse.buildGetSuccessResponse(billService.query(bill));
    }

    /**
     * @api {POST} bill/
     * @apiGroup balance-bill
     * @apiDescription 手动增加账单
     * @apiParamExample 请求样例：
     * http://localhost:9002/balance-bill/bill
     * {billType: "1", billAttribution: 87, total: "2", remark: "2"}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"201","msg":"保存成功！","data":{"rows":[{"id":1,"billType":1,"payState":0,"billTime":"2018-05-10 08:58:53","payTime":null,"billAttribution":1,"lastRead":"22","lastReadTime":"2018-05-10 08:59:02","thisRead":"22","thisReadTime":"2018-05-10 08:59:05","absoluteNumber":"121","price":"1","total":"1","paySerial":""}],"total":1,"size":0}}
     */
    @PostMapping("")
    public CommonResponse add(@RequestBody Bill bill) {
        return CommonResponse.buildAddSuccessResponse(billService.add(bill));
    }

    /**
     * @api {POST} bill/rent/list
     * @apiGroup balance-bill
     * @apiDescription 查询账单（分页）
     * @apiParamExample 请求样例：
     * http://localhost:9002/balance-bill/bill/rent/list
     * {"num":"0","size":"8","query":{"communityId":-1,"housesId":-1,"billType":-1,"payState":-1,"expression":""}}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":{"rows":[{"id":1,"billType":1,"payState":1,"billTime":"2018-05-10 08:58:53","payTime":"2018-05-10 08:00:00","billAttribution":1,"lastRead":"22","lastReadTime":"2018-05-10 08:59:02","thisRead":"22","thisReadTime":"2018-05-10 08:59:05","absoluteNumber":"121","price":"1","total":"1","paySerial":"11111","wxopenId":null,"tenantName":null,"tenantTel":null,"houseNumb":null,"building":null,"unit":null,"address":null,"community":null,"communityId":null,"expression":null},{"id":2,"billType":2,"payState":1,"billTime":"2018-05-10 08:58:53","payTime":"2018-05-10 08:00:00","billAttribution":1,"lastRead":"22","lastReadTime":"2018-05-10 08:59:02","thisRead":"22","thisReadTime":"2018-05-10 08:59:05","absoluteNumber":"121","price":"1","total":"1","paySerial":"11111","wxopenId":null,"tenantName":null,"tenantTel":null,"houseNumb":null,"building":null,"unit":null,"address":null,"community":null,"communityId":null,"expression":null}],"total":2,"size":0}}
     */
    @PostMapping("rent/list")
    public CommonResponse queryRentBill(@RequestBody PageRequest<RentBill> request) {
        Employee employee = authcService.getCurrentUser().getData();
        if (employee != null && !employee.getRoles().equals(EmployeeRoleCons.ADMIN)) {//超级管理员
            request.getQuery().setEnterpriseId(employee.getEnterpriseId());
        }
        return CommonResponse.buildGetSuccessResponse(billService.queryRentBill(request));
    }

    /**
     * @api {POST} bill/rent/list_fj
     * @apiGroup balance-bill
     * @apiDescription 查询账单（分页）==按房间
     * @apiParamExample 请求样例：
     * http://localhost:9002/balance-bill/bill/rent/list_fj
     * {"num":"0","size":"8","query":{"communityId":-1,"housesId":-1,"billType":-1,"payState":-1,"expression":""}}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":{"rows":[{"id":1,"billType":1,"payState":1,"billTime":"2018-05-10 08:58:53","payTime":"2018-05-10 08:00:00","billAttribution":1,"lastRead":"22","lastReadTime":"2018-05-10 08:59:02","thisRead":"22","thisReadTime":"2018-05-10 08:59:05","absoluteNumber":"121","price":"1","total":"1","paySerial":"11111","wxopenId":null,"tenantName":null,"tenantTel":null,"houseNumb":null,"building":null,"unit":null,"address":null,"community":null,"communityId":null,"expression":null},{"id":2,"billType":2,"payState":1,"billTime":"2018-05-10 08:58:53","payTime":"2018-05-10 08:00:00","billAttribution":1,"lastRead":"22","lastReadTime":"2018-05-10 08:59:02","thisRead":"22","thisReadTime":"2018-05-10 08:59:05","absoluteNumber":"121","price":"1","total":"1","paySerial":"11111","wxopenId":null,"tenantName":null,"tenantTel":null,"houseNumb":null,"building":null,"unit":null,"address":null,"community":null,"communityId":null,"expression":null}],"total":2,"size":0}}
     */
    @PostMapping("rent/list_fj")
    public CommonResponse queryRentBillByHouse(@RequestBody PageRequest<RentBill> request) {
        Employee employee = authcService.getCurrentUser().getData();
        if (employee != null && !employee.getRoles().equals(EmployeeRoleCons.ADMIN)) {//超级管理员
            request.getQuery().setEnterpriseId(employee.getEnterpriseId());
        }
        return CommonResponse.buildGetSuccessResponse(billService.queryRentBillByHouse(request));
    }
    /**
     * @api {POST} bill/rent/list_zk
     * @apiGroup balance-bill
     * @apiDescription 查询账单（分页）==按租客
     * @apiParamExample 请求样例：
     * http://localhost:9002/balance-bill/bill/rent/list_zk
     * {"num":"0","size":"8","query":{"communityId":-1,"housesId":-1,"billType":-1,"payState":-1,"expression":""}}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":{"rows":[{"id":1,"billType":1,"payState":1,"billTime":"2018-05-10 08:58:53","payTime":"2018-05-10 08:00:00","billAttribution":1,"lastRead":"22","lastReadTime":"2018-05-10 08:59:02","thisRead":"22","thisReadTime":"2018-05-10 08:59:05","absoluteNumber":"121","price":"1","total":"1","paySerial":"11111","wxopenId":null,"tenantName":null,"tenantTel":null,"houseNumb":null,"building":null,"unit":null,"address":null,"community":null,"communityId":null,"expression":null},{"id":2,"billType":2,"payState":1,"billTime":"2018-05-10 08:58:53","payTime":"2018-05-10 08:00:00","billAttribution":1,"lastRead":"22","lastReadTime":"2018-05-10 08:59:02","thisRead":"22","thisReadTime":"2018-05-10 08:59:05","absoluteNumber":"121","price":"1","total":"1","paySerial":"11111","wxopenId":null,"tenantName":null,"tenantTel":null,"houseNumb":null,"building":null,"unit":null,"address":null,"community":null,"communityId":null,"expression":null}],"total":2,"size":0}}
     */
    @PostMapping("rent/list_zk")
    public CommonResponse queryRentBillByTenant(@RequestBody PageRequest<RentBill> request) {
        Employee employee = authcService.getCurrentUser().getData();
        if (employee != null && !employee.getRoles().equals(EmployeeRoleCons.ADMIN)) {//超级管理员
            request.getQuery().setEnterpriseId(employee.getEnterpriseId());
        }
        return CommonResponse.buildGetSuccessResponse(billService.queryRentBillByTenant(request));
    }

    /**
     *  查询日账单明细
     *  */
    @PostMapping("rent/queryDayBillByRentId")
    public CommonResponse queryDayBillByRentId(@RequestBody PageRequest<RentBill> request) {
        return CommonResponse.buildGetSuccessResponse(billService.queryDayBillByRentId(request));
    }
    /**
     * 查账单总金额
     *  */
    @PostMapping("rent/queryDayBillSumByRentId")
    public CommonResponse queryDayBillSumByRentId(@RequestBody RentBill request) {
        return CommonResponse.buildGetSuccessResponse(billService.queryDayBillSumByRentId(request));
    }
    /**
     * @api {GET} bill/total/{billAttribution}
     * @apiGroup balance-bill
     * @apiDescription 根据账单归属统计未缴账单
     * @apiParamExample 请求样例：
     * http://localhost:9002/balance-bill/bill/total/1
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":{"total":"1","bills":[{"id":1,"billType":1,"payState":0,"billTime":"2018-05-10 08:58:53","payTime":null,"billAttribution":1,"lastRead":"22","lastReadTime":"2018-05-10 08:59:02","thisRead":"22","thisReadTime":"2018-05-10 08:59:05","absoluteNumber":"121","price":"1","total":"1","paySerial":""}]}}
     */
    @GetMapping("{billAttribution}")
    public CommonResponse getTotalUnpayed(@PathVariable Long billAttribution) {
        return CommonResponse.buildGetSuccessResponse(billService.getTotalUnpayed(billAttribution));
    }

    /**
     * @api {DELETE} bill/state/{billId}
     * @apiGroup balance-bill
     * @apiDescription 客户端删除账单显示
     * @apiParamExample 请求样例：
     * http://localhost:9002/balance-bill/bill/state/1
     * @apiSuccessExample {json} 返回样例:
     * {"status":"204","msg":"删除成功！","data":""}}
     */
    @DeleteMapping("state/{billId}")
    public CommonResponse updateState(@PathVariable Long billId) {
        billService.updateState(billId);
        return CommonResponse.buildDelSuccessResponse("");
    }
    /**
     * @api {POST} bill/state
     * @apiGroup balance-bill
     * @apiDescription 客户端删除账单显示
     * @apiParamExample 请求样例：
     * http://localhost:9002/balance-bill/bill/state
     * [1,2,3]
     * @apiSuccessExample {json} 返回样例:
     * {"status":"204","msg":"删除成功！","data":""}}
     */
    @PostMapping("state")
    public CommonResponse updateState(@RequestBody Long[] billIds) {
        Arrays.stream(billIds).forEach(billId-> billService.updateState(billId));
        return CommonResponse.buildDelSuccessResponse("");
    }

    /**
     * @api {POST} bill/employee/rent-bill
     * @apiGroup balance-bill
     * @apiDescription 公寓管理员获取租客缴费信息及租房信息 ( state: 0:所有 1:欠费 默认查询欠费)
     * @apiParamExample 请求样例：
     * http://localhost:9002/balance-bill/bill/employee/rent-bill
     * {"num":"0","size":"8","query":{"state":1}}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":{"rows":[{"tenantId":1,"tenantName":"2123","tenantTel":"123","cardId":null,"community":"123","houseNumb":"123","address":null,"rentState":1,"rentStateName":"租住","billPayState":"正常","arrearage":"0.00","delayDays":0,"bills":[{"id":1,"billType":1,"payState":0,"billTime":"2018-05-10 08:58:53","payTime":null,"billAttribution":1,"lastRead":"22","lastReadTime":"2018-05-10 08:59:02","thisRead":"22","thisReadTime":"2018-05-10 08:59:05","absoluteNumber":"121","price":"1","total":"1","paySerial":""}]}],"total":1,"size":0}}
     */
    @PostMapping("employee/rent-bill")
    public CommonResponse getRentBillCountPage(@RequestBody PageRequest<RentBillCountQuery> request) {
        Employee employee = authcService.getCurrentUser().getData();
        if (employee != null && !employee.getRoles().equals(EmployeeRoleCons.ADMIN)) {//超级管理员
            request.getQuery().setEnterpriseId(employee.getEnterpriseId());
        }
        return CommonResponse.buildGetSuccessResponse(billService.getRentBillCountPage(request));
    }

    /**
     * @api {POST} bill/employee
     * @apiGroup balance-bill
     * @apiDescription 公寓管理员获取相关支付账单 ( state: 1已支付，0未支付)
     * @apiParamExample 请求样例：
     * http://localhost:9002/balance-bill/bill/employee
     * {"num":"0","size":"8","query":{"state":1}}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":{"rows":[{"id":1,"billType":1,"payState":1,"billTime":"2018-05-10 08:58:53","payTime":"2018-05-10 08:00:00","billAttribution":1,"lastRead":"22","lastReadTime":"2018-05-10 08:59:02","thisRead":"22","thisReadTime":"2018-05-10 08:59:05","absoluteNumber":"121","price":"1","total":"1","paySerial":"11111","state":null},{"id":2,"billType":2,"payState":1,"billTime":"2018-05-10 08:58:53","payTime":"2018-05-10 08:00:00","billAttribution":1,"lastRead":"22","lastReadTime":"2018-05-10 08:59:02","thisRead":"22","thisReadTime":"2018-05-10 08:59:05","absoluteNumber":"121","price":"1","total":"1","paySerial":"11111","state":null},{"id":3,"billType":3,"payState":1,"billTime":"2018-05-10 08:58:53","payTime":"2018-05-10 08:00:00","billAttribution":1,"lastRead":"22","lastReadTime":"2018-05-10 08:59:02","thisRead":"22","thisReadTime":"2018-05-10 08:59:05","absoluteNumber":"121","price":"1","total":"1","paySerial":"11111","state":null},{"id":4,"billType":4,"payState":1,"billTime":"2018-05-10 08:58:53","payTime":"2018-05-10 08:00:00","billAttribution":1,"lastRead":"22","lastReadTime":"2018-05-10 08:59:02","thisRead":"22","thisReadTime":"2018-05-10 08:59:05","absoluteNumber":"121","price":"1","total":"1","paySerial":"11111","state":null},{"id":5,"billType":5,"payState":1,"billTime":"2018-05-10 08:58:53","payTime":"2018-05-10 08:00:00","billAttribution":1,"lastRead":"22","lastReadTime":"2018-05-10 08:59:02","thisRead":"22","thisReadTime":"2018-05-10 08:59:05","absoluteNumber":"121","price":"1","total":"1","paySerial":"11111","state":null},{"id":6,"billType":6,"payState":1,"billTime":"2018-05-10 08:58:53","payTime":"2018-05-10 08:00:00","billAttribution":1,"lastRead":"22","lastReadTime":"2018-05-10 08:59:02","thisRead":"22","thisReadTime":"2018-05-10 08:59:05","absoluteNumber":"121","price":"1","total":"1","paySerial":"11111","state":null},{"id":7,"billType":7,"payState":1,"billTime":"2018-05-10 08:58:53","payTime":"2018-05-10 08:00:00","billAttribution":1,"lastRead":"22","lastReadTime":"2018-05-10 08:59:02","thisRead":"22","thisReadTime":"2018-05-10 08:59:05","absoluteNumber":"121","price":"1","total":"1","paySerial":"11111","state":null}],"total":7,"size":0}}
     */
    @PostMapping("employee")
    public CommonResponse getEnterpriseBills(@RequestBody PageRequest<RentBillCountQuery> request) {
        Employee employee = authcService.getCurrentUser().getData();
        if (employee != null && !employee.getRoles().equals(EmployeeRoleCons.ADMIN)) {//超级管理员
            request.getQuery().setEnterpriseId(employee.getEnterpriseId());
        }
        return CommonResponse.buildGetSuccessResponse(billService.getEnterpriseBills(request));
    }

    /**
     * @api {GET} bill/month-count/now
     * @apiGroup balance-bill
     * @apiDescription 财务月统计
     * @apiParamExample 请求样例：
     * http://localhost:9002/balance-bill/bill/month-count/now
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":{"phone":"18013897594","actualTotal":"累计实收","expectTotal":"累计应收","monthActualTotal":"月实收","monthExpectTotal":"月应收","countMonth":"2018/05","monthBaseActual":"月房租物业固定实收","monthBaseExpect":"月房租物业固定应收","monthReadingActual":"月水电实收","monthReadingExpect":"月水电应收"}}
     */
    @GetMapping("month-count/now")
    public CommonResponse getEmployeeBillCountNow() {
        Long enterpriseId = 0L;
        Employee employee = authcService.getCurrentUser().getData();
        if (employee != null && !employee.getRoles().equals(EmployeeRoleCons.ADMIN)) {//超级管理员
            enterpriseId = employee.getEnterpriseId();
        }
        return CommonResponse.buildGetSuccessResponse(billService.getEmployeeBillCountNow(enterpriseId));
    }


    /**
     * @api {GET} bill/homePage/getCnt
     * @apiGroup balance-bill
     * @apiDescription 首页统计显示
     * @apiParamExample 请求样例：
     * http://localhost:9002/balance-bill/bill/homePage/getCnt
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":{"phone":"18013897594","cnt1":"空置","cnt2":"预约","cnt3":"预定","cnt4":"维修","cnt5":"投诉"}}
     */
    @GetMapping("homePage/getCnt")
    public CommonResponse getHomePageCnt() {
        Long enterpriseId = 0L;
        Employee employee = authcService.getCurrentUser().getData();
        if (employee != null && !employee.getRoles().equals(EmployeeRoleCons.ADMIN)) {//超级管理员
            enterpriseId = employee.getEnterpriseId();
        }
        return CommonResponse.buildGetSuccessResponse(billService.getHomePageCnt(enterpriseId));
    }

    /**
     * @api {POST} bill/month-count/list
     * @apiGroup balance-bill
     * @apiDescription 财务月统计 分页
     * @apiParamExample 请求样例：
     * http://localhost:9002/balance-bill/bill/month-count/list
     * {"num":"0","size":"8","query":""}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":{"rows":[{"status":"200","msg":"查询成功！","data":{"phone":"18013897594","actualTotal":"累计实收","expectTotal":"累计应收","monthActualTotal":"月实收","monthExpectTotal":"月应收","countMonth":"2018/05","monthBaseActual":"月房租物业固定实收","monthBaseExpect":"月房租物业固定应收","monthReadingActual":"月水电实收","monthReadingExpect":"月水电应收"}}],"total":4,"size":2}}
     */
    @PostMapping("month-count/list")
    public CommonResponse getEmployeeBillCountPage(@RequestBody PageRequest<String> request) {
        Long enterpriseId = 0L;
        Employee employee = authcService.getCurrentUser().getData();
        if (employee != null && !employee.getRoles().equals(EmployeeRoleCons.ADMIN)) {//超级管理员
            enterpriseId = employee.getEnterpriseId();
        }
        request.setQuery(String.valueOf(enterpriseId));
        return CommonResponse.buildGetSuccessResponse(billService.getEmployeeBillCountPage(request));
    }

    /**
     * @api {POST} bill/house-bill
     * @apiGroup balance-bill
     * @apiDescription 查询房间所有账单 分页
     * @apiParamExample 请求样例：
     * http://localhost:9002/balance-bill/bill/house-bill
     * {"num":"0","size":"8","query":{"payState":-1,"billType":-1,"housesId":1}}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":{"rows":[{"id":1,"billType":1,"payState":1,"billTime":"2018-05-10 08:58:53","payTime":"2018-05-10 08:00:00","billAttribution":1,"lastRead":"22","lastReadTime":"2018-05-10 08:59:02","thisRead":"22","thisReadTime":"2018-05-10 08:59:05","absoluteNumber":"121","price":"1","total":"1","paySerial":"11111","state":null,"payType":null}],"total":7,"size":7}}
     */
    @PostMapping("house-bill")
    public CommonResponse getBillListByHouseId(@RequestBody PageRequest<HousesBillQuery> request) {
        return CommonResponse.buildGetSuccessResponse(billService.getBillListByHouseId(request));
    }

    /**
     * 内部服务不显示在api上
     * 每月1号生成上月财务月统计
     *
     * @return
     */
    @PostMapping("count/last-month")
    public CommonResponse insertEmployeeBillCount() {
        billService.insertEmployeeBillCount();
        return CommonResponse.buildDefaultSuccessResponse("");
    }

    /**
     * @api {PUT} bill/background/payState
     * @apiGroup balance-bill
     * @apiDescription 后台更新支付状态
     * @apiParamExample 请求样例：
     * http://localhost:9002/balance-bill/bill/background/payState
     * {idArray:[1,2,3],remark:''}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"202","msg":"保存成功！","data":""}
     */
    @PutMapping("background/payState")
    public CommonResponse<List<Bill>> updatePayStateAndBillSate(@RequestBody PayState payState) {
        billService.updatePayStateAndBillSate(payState.getIdArray(), payState.getRemark());
        return CommonResponse.buildUpdateSuccessResponse("");
    }

    /**
     * 退租调用  不显示api
     * 退租结算全部结清更新状态
     *
     * @param rentId
     * @return
     */
    @PutMapping("payState/all/{rentId}")
    public CommonResponse balanceAllBills(@PathVariable Long rentId) {
        billService.balanceAllBills(rentId);
        return CommonResponse.buildUpdateSuccessResponse("");
    }

    /**
     * @api {GET} bill/total/title/{rentId}
     * @apiGroup balance-bill
     * @apiDescription 获取租客所有已租未租总计
     * @apiParamExample 请求样例：
     * http://localhost:9002/balance-bill/bill/total/title/1
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":{"paid":"1","unpaid":"2"}
     */
    @GetMapping("total/title/{rentId}")
    public CommonResponse getTenantBillFinalCount(@PathVariable Long rentId) {
        return CommonResponse.buildGetSuccessResponse(billService.getTenantBillFinalCount(rentId));
    }

    /**
     * 内部服务不显示在api上
     * 每月1号生成上月财务月统计
     *
     * @return
     */
    @PostMapping("count-type/last-month")
    public CommonResponse saveBillCountByTypeModelList() {
        billService.saveBillCountByTypeModelList();
        return CommonResponse.buildDefaultSuccessResponse("");
    }

    /**
     * @api {POST} bill/count-type
     * @apiGroup balance-bill
     * @apiDescription 获取账单分类统计 可以按年月日查询
     * @apiParamExample 请求样例：
     * http://localhost:9002/balance-bill/bill/count-type
     * {"year":2018}  获取年度分类统计
     * {"year":2018,"month":"5"}  获取指定月分类统计
     * {"year":2018,"month":"5","day":12}  获取指定月分类统计
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"请求成功！","data":{"id":null,"countDate":"2018","year":2018,"month":null,"day":null,"enterpriseId":2,"waterTotal":0.0,"powerTotal":0.0,"netTotal":0.0,"estateTotal":0.0,"rentalTotal":0.0}}
     *
     */
    @PostMapping("count-type")
    public CommonResponse getBillCountByTypeAndUserModel(@RequestBody BillCountByTypeQuery query) {
        Employee employee = authcService.getCurrentUser().getData();
        if (employee != null && !employee.getRoles().equals(EmployeeRoleCons.ADMIN)) {//超级管理员
            query.setEnterpriseId(employee.getEnterpriseId());
        }
        return CommonResponse.buildDefaultSuccessResponse(billService.getBillCountByTypeAndUserModel(query));
    }

    /**
     * @api {POST} bill/count-type/year/list
     * @apiGroup balance-bill
     * @apiDescription 获取账单分类统计 某年的月列表
     * @apiParamExample 请求样例：
     * http://localhost:9002/balance-bill/bill/count-type/year/list
     * {"year":2018}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":[{"id":null,"countDate":"2018-06","year":2018,"month":6,"day":null,"enterpriseId":2,"waterTotal":0.0,"powerTotal":0.0,"netTotal":0.0,"estateTotal":0.0,"rentalTotal":0.0}]}
     */
    @PostMapping("count-type/year/list")
    public CommonResponse getBillCountByTypeAndUserModelListByYear(@RequestBody BillCountByTypeQuery query) {
        Employee employee = authcService.getCurrentUser().getData();
        if (employee != null && !employee.getRoles().equals(EmployeeRoleCons.ADMIN)) {//超级管理员
            query.setEnterpriseId(employee.getEnterpriseId());
        }
        return CommonResponse.buildGetSuccessResponse(billService.getBillCountByTypeAndUserModelListByYear(query));
    }
}
